<template>
    <div>
        <Button type="primary" @click="onAdd">添加</Button>
        <Input v-model="filter.name"><!--name为user.control.js里list下的查询条件-->
            <Button slot="append" icon="ios-search" @click="onSearch"></Button>
        </Input>
        <Button type="error" @click="onDeletes">删除多条记录</Button>
        <Table border ref="selection" :columns="columns" :data="filter.list" @on-selection-change="onSelectionChange"></Table>
        <Page :total="filter.total" size="small" 
        show-elevator show-sizer show-total
        @on-change = "onchange"
        @on-page-size-change="onPageSizeChange"
        ></Page>

        <!--添加数据弹窗-->
        <Modal
            v-model="modal"
            title="数据操作">

             <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
                <input type="text" name="_id">
                <FormItem label="姓名" prop="name">
                    <Input v-model="formValidate.name" placeholder="请输入姓名"></Input>
                </FormItem>
                <!-- <FormItem label="密码" prop="password">
                    <Input v-model="formValidate.password" placeholder="请输入密码"></Input>
                </FormItem> -->
                 <FormItem label="年龄" prop="age">
                    <Input v-model="formValidate.age" placeholder="请输入年龄"></Input>
                </FormItem>
                <FormItem label="性别" prop="sex">
                    <RadioGroup v-model="formValidate.sex">
                        <Radio label="男">男</Radio>
                        <Radio label="女">女</Radio>
                    </RadioGroup>
                </FormItem>
                 <FormItem label="手机" prop="phone">
                    <Input v-model="formValidate.phone" placeholder="请输入手机号码"></Input>
                </FormItem>
                 <FormItem label="电话" prop="tel">
                    <Input v-model="formValidate.tel" placeholder="请输入电话号码"></Input>
                </FormItem>
                <FormItem label="邮箱" prop="email">
                    <Input v-model="formValidate.email" placeholder="请输入邮箱"></Input>
                </FormItem>
                <FormItem label="地址" prop="address">
                    <Input v-model="formValidate.address" placeholder="请输入地址"></Input>
                </FormItem>
                <FormItem>
                    <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
                    <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button>
                </FormItem>
            </Form>
            
        </Modal>
    </div>
    
</template>


<script>
    import Base from '../../common/Base';
    export default {
        mixins:[Base],
        data () {
            return {
                module:'users',
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '姓名',
                        key: 'name',
                        width: 100,
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row.name)
                            ]);
                        }
                    },
                    // {
                    //     title: '密码',
                    //     key: 'password',
                    // },
                    {
                        title: '年龄',
                        width: 80,
                        align: 'center',
                        key: 'age',
                        sortable: true
                    },
                    {
                        title: '性别',
                        width: 80,
                        align: 'center',
                        key: 'sex',
                    },
                    {
                        title: '手机',
                        key: 'phone'
                    },
                    {
                        title: '电话',
                        key: 'tel'
                    },
                    {
                        title: '邮箱',
                        key: 'email'
                    },
                    {
                        title: '地址',
                        key: 'address'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.row)
                                        }
                                    }
                                }, '编辑'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            console.log(params)
                                            this.remove(params.row._id)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],
                //添加弹窗的表单
                formValidate: {
                    name: '',
                    password:'',
                    age:'',
                    sex:'',
                    phone:'',
                    tel:'',
                    mail: '',
                    address: '',
                },
                ruleValidate: {
                    name: [
                        { required: true, message: '姓名不能为空', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '密码不能为空', trigger: 'blur' }
                    ],
                    sex: [
                        { message: '请选择性别', trigger: 'change' }
                    ],
                    email: [
                        { message: '邮箱不能为空', trigger: 'blur' },
                        { type: 'email', message: '邮箱格式不正确', trigger: 'blur' }
                    ],
                    address: [
                        { message: '请输入地址', trigger: 'change' }
                    ],
                    
                }
            }
        },
       
    }
</script>
